package com.admin.web.controller;


import com.admin.web.controller.commen.BaseController;
import com.fegin.VO.admin.ContentNewsVO;
import com.fegin.bean.admin.ContentNews;
import com.fegin.client.admin.AdminContentNewsFegin;
import com.util.Respons.ResponseMsg;
import com.util.Respons.ResponseUtil;
import com.util.pageinfoutil.PageUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.Map;

/**
 * 后台新闻管理
 *
 * @author 卫星
 * @package com.admin.controller
 * @date 2019-03-04  14:11
 * @project CurrenCy-Cloud
 */
@Controller
@RequestMapping(value = "admin/news")
public class AdminContentNewsController extends BaseController {
    @Autowired
    AdminContentNewsFegin AdminContentNewsFegin;

    /**
     * 跳转到新闻列表页面
     */
    @RequestMapping(value = "/news_list.html", method = RequestMethod.GET)
    public String NewsList() throws IOException {
        return "contentnews/news_list";
    }

    @RequestMapping(value = "/toEditNews.html", method = RequestMethod.GET)
    @ApiOperation(notes = "id:新闻列表id", value = "文章查询")
    public String toNewsEdit(ContentNews contentNews, Model model) throws IOException {
        Map<String, Object> resultMap = AdminContentNewsFegin.view(contentNews);
        model.addAttribute("newsEdit", resultMap);
        return "contentnews/edit_news";
    }

    /**
     * 单个新闻查看
     *
     * @return
     * @ResponseBody * @param contentNews
     */
    @RequestMapping(value = "view", method = RequestMethod.GET)
    @ApiOperation(notes = "id:新闻列表id", value = "文章查询")
    @ResponseBody
    public Map<String, Object> view(ContentNews contentNews) {
        return AdminContentNewsFegin.view(contentNews);
    }

    /**
     * 分页查看数据
     */
    @RequestMapping(value = "newsList", method = RequestMethod.GET)
    @ApiOperation(notes = "文章查询 ：开始时间 startDate ；结束时间 endDate ;页数 page 每页数量 pageSize", value = "文章查询")
    @ResponseBody
    public Map<String, Object> newsList(ContentNews contentNews, PageUtil pageUtil) {

        return AdminContentNewsFegin.newsList(new ContentNewsVO(pageUtil, contentNews));
    }

    /**
     * 新闻删除
     *
     * @param contentNews
     * @return
     */
    @RequestMapping(value = "del", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(notes = "删除文章 ：文章Id id；", value = "删除文章")
    public Map<String, Object> delNews(ContentNews contentNews) {
        Map<String, Object> resultMap = ResponseUtil.getNotNormalMap(ResponseMsg.EMPTY_PARAM);
        if (contentNews.getId() != null) {
            ContentNews contentNews1 = new ContentNews();
            contentNews1.setId(contentNews.getId());
            resultMap = AdminContentNewsFegin.delNews(contentNews1);
        }
        return resultMap;
    }


}
